<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:geo="http://www.ncbi.nlm.nih.gov/geo/info/MINiML"
	>
	<xsl:template name="printExperimentTable">
		<xsl:param name="experiments" />
		<xsl:param name="GSEs" />
		
		<table class="table">
			<caption>GSE的实验类型</caption>
			<thead>
				<tr>
					<th>类型</th>
					<th>GSE数量</th>
				</tr>
			</thead>
			<tbody>
				<!-- preceding::geo:Type selects geo::Type that belong to preceding terms. -->
				<!-- As a reult, we must tell XSLT that the geo:Type we select is nodes whose ancestors at geo:MINiML level are siblings. -->
				<xsl:for-each select="$experiments">
				<xsl:sort select="text()" />
				<xsl:variable name="type" select="child::node()" />
				
				<tr>
					<td><xsl:value-of select="$type" /></td>
					<td>
						<xsl:value-of select="count($GSEs/geo:Type[text()=$type])" />
					</td>
				</tr>
				</xsl:for-each>
			</tbody>
		</table>
	</xsl:template>
	
	<xsl:template name="printCountryTable">
		<xsl:param name="countries" />
		<xsl:param name="contacts" />
		
		<table class="table">
			<caption>GSE的国家分布</caption>
			<thead>
				<tr>
					<th>国家</th>
					<th>GSE数量</th>
				</tr>
			</thead>
			<tbody>
				<xsl:for-each select="$countries">
				<xsl:sort select="text()" />
				<xsl:variable name="country" select="child::node()" />
				
				<tr>
					<td><xsl:value-of select="$country" /></td>
					<td>
						<xsl:value-of select="count($contacts/geo:Country[text()=$country])" />
					</td>
				</tr>
				</xsl:for-each>
			</tbody>
		</table>
	</xsl:template>
	
	<xsl:template name="printCityTable">
		<xsl:param name="cities" />
		<xsl:param name="contacts" />
		
		<table class="table">
			<caption>GSE的城市分布</caption>
			<thead>
				<tr>
					<th>城市</th>
					<th>国家</th>
					<th>GSE数量</th>
				</tr>
			</thead>
			<tbody>
				<xsl:for-each select="$cities">
				<xsl:sort select="parent::node()/geo:Country" />
				<xsl:variable name="city" select="child::node()" />
				<xsl:variable name="country" select="parent::node()/geo:Country" />
				<tr>
					<td><xsl:value-of select="$city" /></td>
					<td><xsl:value-of select="$country" /></td>
					<td>
						<xsl:value-of select="count($contacts/geo:City[text()=$city])" />
					</td>
				</tr>
				</xsl:for-each>
			</tbody>
		</table>
	</xsl:template>
	
	<xsl:template name="printGSETable">
		<xsl:param name="GSEs" />
		
		<div class="table-responsive">
			<table class="table table-striped">
				<caption>GSE详情</caption>
				<thead>
					<tr>
						<th>序号</th>
						<th>数据库</th>
						<th>Accession</th>
						<th>国家</th>
						<th>城市</th>
						<th>实验类型</th>
						<th>说明</th>
					</tr>
				</thead>
				<tbody>
					<xsl:for-each select="$GSEs">
					<xsl:sort select="geo:Series/geo:Type" />
						<xsl:variable name="contact" select="geo:Contributor[@iid='contrib1']/geo:Address" />
						<tr>
							<td><xsl:number value="position()" /></td>
							<td>GEO</td>
							<td><xsl:value-of select="geo:Series/@iid" /></td>
							<td><xsl:value-of select="$contact/geo:Country" /></td>
							<td><xsl:value-of select="$contact/geo:City" /></td>
							<td><xsl:value-of select="geo:Series/geo:Type" /></td>
							<td><xsl:value-of select="geo:Series/geo:Overall-Design" /></td>
						</tr>
					</xsl:for-each>
				</tbody>
			</table>
		</div>
	</xsl:template>
</xsl:stylesheet>